# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=ruby-unicode-display_width
_pkgname="${pkgname#ruby-}"
pkgver=2.4.2
pkgrel=1
pkgdesc='Determines the monospace display width of a string in Ruby'
arch=('any')
url='https://github.com/janlelis/unicode-display_width'
license=('MIT')
depends=('ruby')
makedepends=('git' 'ruby-rdoc')
checkdepends=('ruby-rake' 'ruby-rspec' 'ruby-unicode-emoji')
options=('!emptydirs')
_commit='3362ebcfa5a25b8a780d72a75944579e84d4ba16'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  gem build "$_pkgname.gemspec" 
}

check() {
  cd "$pkgname"

  rake test
}

package() {
  cd "$pkgname"

  local _gemdir="$(ruby -e'puts Gem.default_dir')"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_pkgname-$pkgver.gem"

  # delete cache
  rm -vrf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/MIT-LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname"
}
